<template>
	<view class="content">
		<image :src="baseUrl+'/img/juanjiahui/banquet1.jpg'" class="head"></image>
		<view class="selectBox">
			<text class="selectLabel">场地选择 :</text>
			<text class="selectA" :class="typeIndex==1?'selectActive':''" @click="changType(1)">A</text>
			<text class="selectLine">/</text>
			<text class="selectB" :class="typeIndex==2?'selectActive':''" @click="changType(2)">B</text>
		</view>
		<view class="infoBox">
			<swiper class="swiperBox">
				<swiper-item class="swiperItem" v-for="(item,index) in plate.banner" :key="index">
					<image :src="item.url" class="swiperItem"></image>
				</swiper-item>
			</swiper>
			<view class="navigationBox">
				<view class="nameBox">
					<text>{{plate.name}}</text>
					<text>￥{{plate.price}}</text>
				</view>
				<view class="addressBox">
					<text>容纳人数 ：{{plate.num}} 人</text>
					<text style="margin-top: 25rpx;">地 址 ：{{plate.address}}</text>
					<image :src="baseUrl+'img/juanjiahui/navigation.png'" class="navigation"></image>
				</view>
			</view>
		</view>
		<view class="orderTimeBox">
			<view class="titleBox">
				<text class="title">场地预约</text>
				<view class="notBlock">
				</view>
				<text class="notLabel">不可预约</text>
				<view class="canBox">
					<view class="canBlock">
					</view>
					<text class="canLabel">已选择</text>
				</view>
			</view>
			<view class="item">
				<text class="left">人数：</text>
				<input type="text" class="right" placeholder="请输入就餐人数" v-model="num" />
			</view>
			<view class="dateBox">
				<text class="month">{{monthValue}}</text>
				<view class="triangle">
				</view>
				<view class="line">
				</view>
				<scroll-view class="dateScrollBox" scroll-x="true" :scroll-into-view="dateId">
					<view class="dateItem" :class="dateIndex==index?'dateActive':''" :id="`item-${index}`"
						v-for="(item,index) in dateArr" :key="index" @click="selDate(index)">
						{{item}}
					</view>
				</scroll-view>
				<uni-section class="selecteMonth">
					<uni-data-select v-mode="monthValue" :localdata="month" @change="changeMonth()" />
					</uni-data-select>
				</uni-section>
			</view>
			<view class="timeBox">
				<scroll-view class="timeScrollBox" scroll-x="true" :scroll-into-view="timeId">
					<view class="timeItem" :class="{'tiemActive': timeIndex === index,'timeDisable': !item.status}"
						:id="`item-${index}`" v-for="(item,index) in timeArr" :key="index"
						@click="selTime(index,item.status)">
						{{item.time_frame}}
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="cartBox">
			<text class="totalLabel">定金：</text>
			<text class="totalPrice">￥{{plate.price}}</text>
			<view class="submit" @click="submit">
				下一步
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				baseUrl: this.$baseUrl,
				typeIndex: 1,
				month: [],
				monthValue: '',
				value: 0,
				data: '',
				plate: '',
				timeArr: [], //可预约时段
				timeIndex: -1,
				time: '',
				service_data: '',
				dateArr: [],
				dateIndex: -1,
				date: '',
				yearArr: [],
				nextMonth: 0,
				dateId: '',
				timeId: '',
				num:''//就餐人数
			}
		},
		onLoad() {
			this.$request.get('venue_list?type=2').then(res => {
				this.data = res.data.data;
				this.plate = this.data[0];
			})
			this.dateArr = this.$getDateRanges().currentMonthDates //赋值当前月份剩余日期
			this.yearArr[0] = this.$getCurrentAndNextMonthYear().currentMonthYear;
			this.yearArr[1] = this.$getCurrentAndNextMonthYear().nextMonthYear;
			this.month = this.$getFormattedMonths();
			this.monthValue = this.month[0].text;
			this.service_data = this.yearArr[0] + '-' + this.dateArr[0].toString()
				.padStart(2, '0');
			this.getTime()
		},
		methods: {
			submit() {
				if (!this.num || this.num > this.plate.num) {
					return this.$toast('请输入就餐人数且不能大于容纳人数');
				}
				if (!this.date) {
					return this.$toast('请选择日期');
				}
				if (!this.time) {
					return this.$toast('请选择时间');
				}
				this.$store.commit('setTempData', this.$data);
				this.$navto.navto("/pages/juanjiahui_banquet_submit/juanjiahui_banquet_submit")
			},
			changType(num) {
				this.typeIndex = num;
				this.plate = this.data[num - 1];
			},
			getTime() {
				this.$request.post(`sub_time_list`, {
					type: 4,
					service_data: this.service_data,
					sub_type: 4
				}).then(res => {
					this.timeArr = res.data.data;
				})
			},
			// 选择时间
			selTime(index, status) {
				if (!status) {
					return this.$toast("当前时间不可选");
				}
				this.timeIndex = index;
				this.time = this.timeArr[index].time_frame;

			},
			// 选择日期
			selDate(index, status) {
				this.dateIndex = index;
				this.date = this.dateArr[index];
				this.dateArr = this.$getDateRanges().currentMonthDates;
				if (this.nextMonth == 0) {
					this.service_data = this.yearArr[0] + '-' + this.date.toString().padStart(2, '0');
				} else {
					this.service_data = this.yearArr[1] + '-' + this.date.toString().padStart(2, '0');
				}
				this.getTime();
			},
			// 选择月份
			changeMonth(e) {
				this.timeIndex = -1;
				this.dateIndex = -1;
				if (e == 0) { //当前月份
					this.nextMonth = 0;
					console.log(this.$getCurrentAndNextMonthYear().currentMonthYear);
					this.dateArr = this.$getDateRanges().currentMonthDates;
					this.service_data = this.yearArr[0] + '-' + this.dateArr[0].toString().padStart(2, '0');
				} else { //下个月
					this.nextMonth = 1;
					console.log(this.$getCurrentAndNextMonthYear().nextMonthYear);
					this.dateArr = this.$getDateRanges().nextMonthDates;
					this.service_data = this.yearArr[1] + '-' + this.dateArr[0].toString().padStart(2, '0');
				}
				console.log(this.nextMonth)
				this.monthValue = this.month[e].text;
				this.getTime();
				this.dateId = 'item-0';
				this.timeId = 'item-0';
				setTimeout(() => {
					this.dateId = '';
					this.timeId = '';
				}, 1000)
			}
		}
	}
</script>
<style lang="scss" scoped>
	.item {
		width: 670rpx;
		position: relative;
		padding-top: 45rpx;
		padding-bottom: 45rpx;
		border-bottom: 1rpx solid #121212;
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;

		.right {
			font-weight: 500;
			font-size: 26rpx;
			color: #121212;
			display: flex;
			margin-left: auto;
			text-align: right;
			align-items: center;
		}

		.left {
			font-weight: 700;
			font-size: 26rpx;
			color: #121212;
		}
	}

	.cartBox {
		position: fixed;
		z-index: 3;
		bottom: 0;
		width: 100%;
		height: 130rpx;
		background-color: #ffffff;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		padding-left: 40rpx;
		padding-right: 40rpx;
		justify-content: space-between;
		padding-bottom: 20rpx;
		border-top: 1rpx solid #f0f0f0;

		.totalPrice {
			color: #121212;
			font-weight: 700;
			font-size: 34rpx;
			letter-spacing: 2rpx;
		}

		.totalLabel {
			font-weight: 700;
			font-size: 20rpx;
			color: #121212;
		}

		.submit {
			width: 420rpx;
			height: 80rpx;
			border-radius: 40rpx;
			background: #121212;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: 700;
			font-size: 28rpx;
			color: #FFFFFF;
			letter-spacing: 5rpx;
			margin-left: auto;
		}
	}

	.orderTimeBox {
		width: 750rpx;
		background: #ffffff;
		padding: 60rpx 40rpx 200rpx 40rpx;
		border-top: 25rpx solid #f0f0f0;
		// border-bottom: 25rpx solid #f0f0f0;
		// margin-top: 55rpx;

		.timeBox {
			width: 670rpx;
			display: flex;
			align-items: center;
			padding-top: 58rpx;

			.timeScrollBox {
				// width: 450rpx;
				overflow-x: scroll;
				display: flex;
				white-space: nowrap;

				.timeItem {
					// height: 50rpx;
					font-weight: 500;
					font-size: 26rpx;
					color: #121212;
					margin-right: 75rpx;
					flex: 0 0 auto;
					display: inline-flex;
				}

				.tiemActive {
					color: #FF6E5D;
					font-weight: 900;
					// border-bottom: 4rpx solid #FF6E5D;
				}

				.timeDisable {
					color: #8E8E8E;
				}
			}
		}

		.dateBox {
			position: relative;
			width: 670rpx;
			display: flex;
			align-items: center;
			padding-top: 58rpx;
			padding-bottom: 58rpx;
			border-bottom: 1rpx solid #121212;

			.selecteMonth {
				position: absolute;
				left: 0rpx;
				width: 120rpx;
				height: 50%;
			}

			.dateScrollBox {
				// width: 450rpx;
				margin-left: 54rpx;
				display: flex;
				white-space: nowrap;
				overflow-x: scroll;

				.dateItem {
					width: 80rpx;
					height: 80rpx;
					border: 1rpx solid #121212;
					border-radius: 50%;
					// display: flex;
					display: inline-flex;
					font-weight: 500;
					font-size: 26rpx;
					color: #121212;
					align-items: center;
					justify-content: center;
					margin-right: 33rpx;
					flex: 0 0 auto;
					box-sizing: border-box;
				}

				.dateActive {
					background: #FF6E5D;
					// border: none;
					color: #ffffff;
					border: 1rpx solid #FF6E5D;
				}

				.dateDisable {
					background: #f0f0f0;
					border: none;
				}
			}

			.line {
				width: 1rpx;
				height: 44rpx;
				background: #c7c7c7;
				margin-left: 50rpx;
			}

			.triangle {
				width: 24rpx;
				height: 18rpx;
				background: #121212;
				clip-path: polygon(0 0, 100% 50%, 0 100%);
			}

			.month {
				width: 150rpx;
				text-align: center;
				font-weight: 700;
				font-size: 30rpx;
				color: #121212;
				white-space: nowrap;
			}
		}

		.titleBox {
			width: 670rpx;
			display: flex;
			align-items: center;
			padding-bottom: 53rpx;
			border-bottom: 1rpx solid #121212;

			.timeIcon {
				width: 28rpx;
				height: 28rpx;
			}

			.title {
				font-weight: 700;
				font-size: 26rpx;
				color: #121212;
			}

			.notBlock {
				width: 17rpx;
				height: 17rpx;
				background: #f0f0f0;
				margin-left: 290rpx;
			}

			.notLabel {
				font-weight: 500;
				font-size: 20rpx;
				color: #8E8E8E;
				margin-left: 14rpx;
			}

			.canBox {
				display: flex;
				align-items: center;
				margin-left: auto;

				.canBlock {
					width: 17rpx;
					height: 17rpx;
					background: #FF6E5D;
				}

				.canLabel {
					font-weight: 500;
					font-size: 20rpx;
					color: #121212;
					margin-left: 14rpx;
				}
			}

		}
	}

	::v-deep .uni-select {
		border: none;
	}

	::v-deep .uni-select .uni-icons {
	  display: none;
	}

	::v-deep .uni-select__input-box {
		opacity: 0 !important;
	}

	.navigationBox {
		padding: 100rpx 40rpx 65rpx 40rpx;
		box-sizing: border-box;
		background-color: #ffffff;

		.addressBox {
			margin-top: 60rpx;
			font-weight: 500;
			font-size: 20rpx;
			color: #121212;
			display: flex;
			flex-direction: column;
			position: relative;

			.navigation {
				position: absolute;
				width: 21rpx;
				height: 21rpx;
				right: 0;
				bottom: 0;
			}
		}

		.nameBox {
			display: flex;
			font-weight: 700;
			font-size: 32rpx;
			color: #121212;
			justify-content: space-between;
		}
	}

	.swiperBox {
		width: 100%;
		height: 400rpx;
		margin-top: 45rpx;

		.swiperItem {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
	}

	.selectBox {
		width: 100%;
		height: 110rpx;
		background-color: #000;
		border-radius: 20rpx 20rpx 0 0;
		border-top: 1rpx solid #717171;
		margin-top: -30rpx;
		position: relative;
		display: flex;
		align-items: center;

		.selectB {
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			margin-left: 75rpx;
		}

		.selectLine {
			font-weight: 500;
			font-size: 32rpx;
			color: #767676;
			margin-left: 75rpx;
		}

		.selectA {
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			margin-left: 75rpx;
		}

		.selectLabel {
			font-weight: 700;
			font-size: 26rpx;
			color: #FFFFFF;
			letter-spacing: 5rpx;
			margin-left: 40rpx;
		}

		.selectActive {
			color: #FF6E5D;
		}
	}

	.head {
		width: 100%;
		height: 200rpx;
	}

	.content {
		width: 100%;
		height: 100vh;
	}
</style>